package com.falcon.enums;

/** java 映射的类型
 * @author zongf
 * @since 2019-11-30
 */
public enum JavaMappingTypeEnum {

    INTEGER("Integer"),
    LONG("Long"),
    FLOAT("Float"),
    DOUBLE("Double"),
    BIG_INTEGER("BigInteger"),
    BIG_DECIMAL("BigDecimal"),
    DATE("Date"),
    BYTEARRAY("byte[]"),
    STRING("String"),
    BOOLEAN("Boolean"),
    UN_SUPPORT("unsupport");

    private String type;

    JavaMappingTypeEnum(String type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return this.type;
    }

    /** 获取java 类型
     * @param dataType mysql 字段数据类型
     * @param unsigned 是否是无符号整数
     * @param maxIntDigits  最大长度
     * @return JavaMappingType
     * @author zongf
     * @since 2019-11-30
     */
    public static JavaMappingTypeEnum getType(MysqlColumnTypeEnum dataType, boolean unsigned, int maxIntDigits) {

        switch (dataType) {
            case BIT:
                return maxIntDigits == 1? JavaMappingTypeEnum.BOOLEAN : JavaMappingTypeEnum.STRING;
            case TINYINT:
            case SMALLINT:
            case MEDIUMINT:
            case INT:
                return unsigned ? JavaMappingTypeEnum.LONG : JavaMappingTypeEnum.INTEGER;
            case BIGINT:
                return unsigned ? JavaMappingTypeEnum.BIG_INTEGER : JavaMappingTypeEnum.LONG;
            case FLOAT:
                return JavaMappingTypeEnum.FLOAT;
            case DOUBLE:
                return JavaMappingTypeEnum.DOUBLE;
            case DECIMAL:
                return JavaMappingTypeEnum.BIG_DECIMAL;
            case YEAR:
                return JavaMappingTypeEnum.INTEGER;
            case BINARY:
            case VARBINARY:
            case TINYBLOB:
            case BLOB:
            case MEDIUMBLOB:
            case LONGBLOB:
            case CHAR:
            case VARCHAR:
            case TINYTEXT:
            case TEXT:
            case MEDIUMTEXT:
            case LONGTEXT:
                return JavaMappingTypeEnum.STRING;
            case DATE:
            case DATETIME:
            case TIME:
            case TIMESTAMP:
                return JavaMappingTypeEnum.DATE;
            default:
                return JavaMappingTypeEnum.UN_SUPPORT;
        }
    }



}
